package com.ruoyi.quartz.task;

import com.ruoyi.quartz.service.YamlGenerateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Map;

@Component
public class MyTask {
    private static final Logger log = LoggerFactory.getLogger(MyTask.class);

    @Autowired
    private YamlGenerateService yamlGenerateService;

    // 每天凌晨执行
    @Scheduled(cron = "${tts.yaml.generation-cron}")
    public void generateYamlFileTask() {
        log.info("开始执行定时生成YAML文件任务...");
        try {
            //执行定时生成yaml文件任务
            Map<String, Object> result = yamlGenerateService.generateYamlFile();
            log.info(result.get("message").toString());
        } catch (IOException e) {
            log.error("生成YAML文件失败", e);
        } catch (Exception e) {
            log.error("定时任务执行异常", e);
        }
    }
}